<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="Hexo Theme Keep">
    <meta name="description" content="Hexo Theme Keep">
    <meta name="author" content="Da">
    
    <title>
        
            JDBC操作封装工具类 |
        
        Da的个人博客
    </title>
    
<link rel="stylesheet" href="/css/style.css">

    <link rel="shortcut icon" href="/images/logo.svg">
    
<link rel="stylesheet" href="/css/font-awesome.min.css">

    <script id="hexo-configurations">
    let KEEP = window.KEEP || {};
    KEEP.hexo_config = {"hostname":"da9527.gitee.io","root":"/","language":"zh-CN","path":"search.json"};
    KEEP.theme_config = {"toc":{"enable":true,"number":false,"expand_all":false,"init_open":false},"style":{"primary_color":"#CC0000","avatar":"/images/avatar.svg","favicon":"/images/logo.svg","article_img_align":"left","left_side_width":"260px","content_max_width":"920px","hover":{"shadow":true,"scale":true},"first_screen":{"enable":true,"background_img":"/images/bg.svg","description":"我不怕千万人阻挡,只怕自己投降"},"scroll":{"progress_bar":{"enable":false},"percent":{"enable":false}}},"local_search":{"enable":true,"preload":false},"code_copy":{"enable":true,"style":"default"},"pjax":{"enable":true},"lazyload":{"enable":true},"version":"3.4.2"};
    KEEP.language_ago = {"second":"%s 秒前","minute":"%s 分钟前","hour":"%s 小时前","day":"%s 天前","week":"%s 周前","month":"%s 月前","year":"%s 年前"};
  </script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
<div class="progress-bar-container">
    

    
        <span class="pjax-progress-bar"></span>
        <span class="pjax-progress-icon">
            <i class="fas fa-circle-notch fa-spin"></i>
        </span>
    
</div>


<main class="page-container">

    

    <div class="page-main-content">

        <div class="page-main-content-top">
            <header class="header-wrapper">

    <div class="header-content">
        <div class="left">
            <a class="logo-title" href="/">
                Da的个人博客
            </a>
        </div>

        <div class="right">
            <div class="pc">
                <ul class="menu-list">
                    
                        <li class="menu-item">
                            <a class=""
                               href="/"
                            >
                                首页
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/archives"
                            >
                                归档
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/about"
                            >
                                关于
                            </a>
                        </li>
                    
                    
                        <li class="menu-item search search-popup-trigger">
                            <i class="fas fa-search"></i>
                        </li>
                    
                </ul>
            </div>
            <div class="mobile">
                
                    <div class="icon-item search search-popup-trigger"><i class="fas fa-search"></i></div>
                
                <div class="icon-item menu-bar">
                    <div class="menu-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="header-drawer">
        <ul class="drawer-menu-list">
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/">首页</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/archives">归档</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/about">关于</a>
                </li>
            
        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="page-main-content-middle">

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="article-content-container">

        <div class="article-title">
            <span class="title-hover-animation">JDBC操作封装工具类</span>
        </div>

        
            <div class="article-header">
                <div class="avatar">
                    <img src="/images/avatar.svg">
                </div>
                <div class="info">
                    <div class="author">
                        <span class="name">Da</span>
                        
                            <span class="author-label">Lv4</span>
                        
                    </div>
                    <div class="meta-info">
                        <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fas fa-edit"></i>&nbsp;2021-07-09 12:21:54
    </span>
    
    

    
    
        <span class="article-wordcount article-meta-item">
            <i class="fas fa-file-word"></i>&nbsp;<span>2.3k 字</span>
        </span>
    
    
        <span class="article-min2read article-meta-item">
            <i class="fas fa-clock"></i>&nbsp;<span>10 分钟</span>
        </span>
    
    
        <span class="article-pv article-meta-item">
            <i class="fas fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

                    </div>
                </div>
            </div>
        

        <div class="article-content markdown-body">
            <h1 id="对数据库的增删改查进行简单的封装"><a href="#对数据库的增删改查进行简单的封装" class="headerlink" title="对数据库的增删改查进行简单的封装"></a>对数据库的增删改查进行简单的封装</h1><p><strong>先看效果</strong></p>
<p>测试类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> com.da.pojo.Admin;</span><br><span class="line"><span class="keyword">import</span> com.da.pojo.Login;</span><br><span class="line"><span class="keyword">import</span> com.da.utlis.DbUtils;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span>: TODO(测试工具类)</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> da</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2021/7/9 下午 12:11</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Test</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"><span class="comment">//        通用的查询</span></span><br><span class="line">        String sql = <span class="string">&quot;select * from login&quot;</span>;</span><br><span class="line">        DbUtils.executeDQL(sql, Login.class).forEach(System.out::println);</span><br><span class="line">        System.out.println(<span class="string">&quot;================&quot;</span>);</span><br><span class="line">        sql = <span class="string">&quot;select * from admin&quot;</span>;</span><br><span class="line">        DbUtils.executeDQL(sql, Admin.class).forEach(System.out::println);</span><br><span class="line"><span class="comment">//        更新操作</span></span><br><span class="line">        sql = <span class="string">&quot;update admin set pwd = ? where name = ?&quot;</span>;</span><br><span class="line">        <span class="keyword">boolean</span> updateCode = DbUtils.executeDML(sql, <span class="string">&quot;666&quot;</span>, <span class="string">&quot;cs&quot;</span>);</span><br><span class="line">        System.out.println(updateCode ? <span class="string">&quot;操作成功&quot;</span> : <span class="string">&quot;操作失败&quot;</span>);</span><br><span class="line"><span class="comment">//        增加操作</span></span><br><span class="line">        sql = <span class="string">&quot;insert into admin values(?,?)&quot;</span>;</span><br><span class="line">        <span class="keyword">boolean</span> insertCode = DbUtils.executeDML(sql, <span class="string">&quot;阿giao&quot;</span>, <span class="string">&quot;giao&quot;</span>);</span><br><span class="line">        System.out.println(insertCode ? <span class="string">&quot;操作成功&quot;</span> : <span class="string">&quot;操作失败&quot;</span>);</span><br><span class="line"><span class="comment">//        删除操作</span></span><br><span class="line">        sql = <span class="string">&quot;delete from admin where name = ?&quot;</span>;</span><br><span class="line">        <span class="keyword">boolean</span> delCode = DbUtils.executeDML(sql, <span class="string">&quot;giao&quot;</span>);</span><br><span class="line">        System.out.println(delCode ? <span class="string">&quot;操作成功&quot;</span> : <span class="string">&quot;操作失败&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>看看结果</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">Login&#123;id=1, name=<span class="string">&#x27;admin&#x27;</span>, password=<span class="string">&#x27;root&#x27;</span>, age=20&#125;</span><br><span class="line">Login&#123;id=2, name=<span class="string">&#x27;root&#x27;</span>, password=<span class="string">&#x27;123456&#x27;</span>, age=21&#125;</span><br><span class="line">Login&#123;id=3, name=<span class="string">&#x27;zhangsan&#x27;</span>, password=<span class="string">&#x27;1234&#x27;</span>, age=18&#125;</span><br><span class="line">================</span><br><span class="line">Admin&#123;name=<span class="string">&#x27;root&#x27;</span>, <span class="built_in">pwd</span>=<span class="string">&#x27;root&#x27;</span>&#125;</span><br><span class="line">Admin&#123;name=<span class="string">&#x27;da&#x27;</span>, <span class="built_in">pwd</span>=<span class="string">&#x27;root2&#x27;</span>&#125;</span><br><span class="line">Admin&#123;name=<span class="string">&#x27;cs&#x27;</span>, <span class="built_in">pwd</span>=<span class="string">&#x27;666&#x27;</span>&#125;</span><br><span class="line">Admin&#123;name=<span class="string">&#x27;阿giao&#x27;</span>, <span class="built_in">pwd</span>=<span class="string">&#x27;giao&#x27;</span>&#125;</span><br><span class="line">Admin&#123;name=<span class="string">&#x27;giao&#x27;</span>, <span class="built_in">pwd</span>=<span class="string">&#x27;giao&#x27;</span>&#125;</span><br><span class="line">操作成功</span><br><span class="line">操作成功</span><br><span class="line">操作成功</span><br></pre></td></tr></table></figure>



<p>是不是还不错，但是还是有很多缺点的，比如sql语句要自己写，表中字段不能用_符号命名，不然无法注入对应的实体类……话不多说，开始封装吧</p>
<h2 id="开始封装"><a href="#开始封装" class="headerlink" title="开始封装"></a>开始封装</h2><p>创建一个普通的maven项目，在pom.xml文件加入mysql数据库连接驱动依赖(我这里是mysql8.0，注意使用你自己的对应版本的mysql驱动)</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>mysql<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mysql-connector-java<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>8.0.25<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>



<p>创建<strong>mysql.properties</strong>(注意名字不要打错了)配置文件，用来配置数据库连接的信息(<strong>注意修改成你的配置信息</strong>)，放在<strong>resources</strong>资源目录下</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">user</span>=<span class="string">root</span></span><br><span class="line"><span class="attr">password</span>=<span class="string">123456</span></span><br><span class="line"><span class="attr">url</span>=<span class="string">jdbc:mysql://localhost:3306/demo?characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=UTC&amp;rewriteBatchedStatements=true</span></span><br><span class="line"><span class="attr">driver</span>=<span class="string">com.mysql.cj.jdbc.Driver</span></span><br></pre></td></tr></table></figure>



<h2 id="最主要的工具类"><a href="#最主要的工具类" class="headerlink" title="最主要的工具类"></a>最主要的工具类</h2><p>创建DbUtils.java(工具类)，获取配置文件是通过反射拿到mysql.properties文件的位置，然后通过Properties读取配置文件，获取连接数据库的信息从而获取数据库连接。executeDML()通过传进来的sql语句和params可变参数来操作数据库，填充sql语句中的?是通过遍历params可变参数逐个给？赋值。executeDQL()通过传进来的sql语句和实体类类型以及params可变参数，来通过查询出的结果集的每一列的列名对应的值给实体类对应的属性赋值然后存入List集合返回。</p>
<p><strong>通过结果集给实体类赋值的重要操作如下</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">resultSet = statement.executeQuery();<span class="comment">//获取结果集</span></span><br><span class="line"><span class="comment">//        可以通过ResultSet获取当前有那些列</span></span><br><span class="line">ResultSetMetaData metaData = resultSet.getMetaData();<span class="comment">//元数据,可以通过它获取表中的列</span></span><br><span class="line"><span class="comment">//        获取表中列的总数</span></span><br><span class="line"><span class="keyword">int</span> columnCount = metaData.getColumnCount();</span><br><span class="line"><span class="comment">//判断是否有记录,然后再根据列名获取每列的信息</span></span><br><span class="line"><span class="keyword">while</span> (resultSet.next())</span><br><span class="line">&#123;<span class="comment">//每次循环获取的是一列数据</span></span><br><span class="line">    <span class="comment">//我们现在不能确定传入的实体类,这里用泛型替代,当你传入实体类型时确定</span></span><br><span class="line">    T t = clazz.newInstance();</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= columnCount; i++)<span class="comment">//循环要从1开始</span></span><br><span class="line">    &#123;<span class="comment">//遍历列数,获取每一列的名字</span></span><br><span class="line">        String columnLabel = metaData.getColumnLabel(i);<span class="comment">//列名</span></span><br><span class="line">        <span class="comment">//                通过列名获取对应列的数据</span></span><br><span class="line">        Object object = resultSet.getObject(columnLabel);</span><br><span class="line">        <span class="comment">//                    通过列名获取实体类中的属性名</span></span><br><span class="line">        Field field = clazz.getDeclaredField(columnLabel);</span><br><span class="line">        <span class="comment">//                    给获取的实体类的属性赋值</span></span><br><span class="line">        field.setAccessible(<span class="keyword">true</span>);<span class="comment">//取消安全检查</span></span><br><span class="line">        field.set(t, object);<span class="comment">//给t对象设置从数据库中查询出来的object值</span></span><br><span class="line">        field.setAccessible(<span class="keyword">false</span>);<span class="comment">//开启安全检查</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p><strong>DbUtils.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"><span class="keyword">import</span> java.lang.reflect.Field;</span><br><span class="line"><span class="keyword">import</span> java.net.URL;</span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Properties;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span>: TODO(操作数据库的工具类)</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> da</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2021/7/9 上午 10:39</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@SuppressWarnings(&quot;all&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DbUtils</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="comment">//连接数据库的信息</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> String user = <span class="string">&quot;&quot;</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> String password = <span class="string">&quot;&quot;</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> String url = <span class="string">&quot;&quot;</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> String driver = <span class="string">&quot;&quot;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//    获取连接的方法</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Connection <span class="title">getConnection</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        Connection connection = <span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span></span><br><span class="line">        &#123;</span><br><span class="line"><span class="comment">//        通过反射获取配置文件位置</span></span><br><span class="line">            URL resource = DbUtils.class.getResource(<span class="string">&quot;/&quot;</span>);</span><br><span class="line">            File filePath = <span class="keyword">new</span> File(resource.getFile());</span><br><span class="line">            File[] files = filePath.listFiles();</span><br><span class="line">            File configFile = <span class="keyword">null</span>;<span class="comment">//配置文件路径</span></span><br><span class="line">            <span class="keyword">for</span> (File file : files)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">if</span> (!file.isDirectory())<span class="comment">//不是文件夹</span></span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">if</span> (file.getName().equals(<span class="string">&quot;mysql.properties&quot;</span>))<span class="comment">//文件名为mysql.properties</span></span><br><span class="line">                    &#123;</span><br><span class="line">                        configFile = <span class="keyword">new</span> File(file.getPath());<span class="comment">//确定配置文件</span></span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (configFile == <span class="keyword">null</span>)</span><br><span class="line">            &#123;<span class="comment">//如果没有mysql.properties配置文件就抛出异常</span></span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> Exception(<span class="string">&quot;小老弟,检查检查配置文件mysql.properties有没有&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line"><span class="comment">//        通过Properties读取配置文件</span></span><br><span class="line">            Properties properties = <span class="keyword">new</span> Properties();</span><br><span class="line">            properties.load(<span class="keyword">new</span> FileInputStream(configFile));</span><br><span class="line"><span class="comment">//        获取连接数据库的信息</span></span><br><span class="line">            user = properties.getProperty(<span class="string">&quot;user&quot;</span>);</span><br><span class="line">            password = properties.getProperty(<span class="string">&quot;password&quot;</span>);</span><br><span class="line">            url = properties.getProperty(<span class="string">&quot;url&quot;</span>);</span><br><span class="line">            driver = properties.getProperty(<span class="string">&quot;driver&quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//        获取数据库连接</span></span><br><span class="line">            Class.forName(driver);<span class="comment">//加载驱动</span></span><br><span class="line">            connection = DriverManager.getConnection(url, user, password);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e)</span><br><span class="line">        &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> connection;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 执行增删改语句的方法</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sql    要执行的sql语句</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> params 条件参数(?对应的值)</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">executeDML</span><span class="params">(String sql, Object... params)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        Connection connection = <span class="keyword">null</span>;</span><br><span class="line">        PreparedStatement statement = <span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span></span><br><span class="line">        &#123;</span><br><span class="line"><span class="comment">//        获取连接和操作数据库的对象</span></span><br><span class="line">            connection = getConnection();</span><br><span class="line">            statement = connection.prepareStatement(sql);</span><br><span class="line"><span class="comment">//            设置参数,如果params不为空说明要设置参数</span></span><br><span class="line">            <span class="keyword">if</span> (<span class="keyword">null</span> != params)</span><br><span class="line">            &#123;</span><br><span class="line"><span class="comment">//                循环遍历设置参数</span></span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; params.length; i++)</span><br><span class="line">                &#123;</span><br><span class="line"><span class="comment">//                    从第一位开始对应赋值</span></span><br><span class="line">                    statement.setObject(i + <span class="number">1</span>, params[i]);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"><span class="comment">//            返回操作结果,如果大于0说明操作成功</span></span><br><span class="line">            <span class="keyword">int</span> resultCode = statement.executeUpdate();</span><br><span class="line">            <span class="keyword">if</span> (resultCode &gt; <span class="number">0</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">            &#125; <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> Exception(<span class="string">&quot;看看语句或者参数写错没有,小老弟&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e)</span><br><span class="line">        &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">finally</span></span><br><span class="line">        &#123;</span><br><span class="line"><span class="comment">//            关闭连接</span></span><br><span class="line">            close(connection, statement, <span class="keyword">null</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;<span class="comment">//如果执行异常,默认返回false</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 通用的查询方法</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> sql    要执行的sql语句</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> clazz  对应的实体类</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> params 条件参数(?对应的值)</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> &lt;T&gt;    对应的实体类型</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line"><span class="comment">//    T表示集合中使用的泛型,Class&lt;T&gt; clazz就是对应的实体类</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> &lt;T&gt; <span class="function">List&lt;T&gt; <span class="title">executeDQL</span><span class="params">(String sql, Class&lt;T&gt; clazz, Object... params)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        Connection connection = <span class="keyword">null</span>;</span><br><span class="line">        PreparedStatement statement = <span class="keyword">null</span>;</span><br><span class="line">        ResultSet resultSet = <span class="keyword">null</span>;</span><br><span class="line">        List&lt;T&gt; list = <span class="keyword">null</span>;<span class="comment">//存放实体类的集合</span></span><br><span class="line">        <span class="keyword">try</span></span><br><span class="line">        &#123;</span><br><span class="line">            connection = getConnection();<span class="comment">//获取连接</span></span><br><span class="line">            statement = connection.prepareStatement(sql);<span class="comment">//执行sql语句</span></span><br><span class="line">            <span class="comment">//            设置参数,如果params不为空说明要设置参数</span></span><br><span class="line">            <span class="keyword">if</span> (<span class="keyword">null</span> != params)</span><br><span class="line">            &#123;</span><br><span class="line"><span class="comment">//                循环遍历设置参数</span></span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; params.length; i++)</span><br><span class="line">                &#123;</span><br><span class="line"><span class="comment">//                    从第一位开始对应赋值</span></span><br><span class="line">                    statement.setObject(i + <span class="number">1</span>, params[i]);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            resultSet = statement.executeQuery();<span class="comment">//获取结果集</span></span><br><span class="line"><span class="comment">//        可以通过ResultSet获取当前有那些列</span></span><br><span class="line">            ResultSetMetaData metaData = resultSet.getMetaData();<span class="comment">//元数据,可以通过它获取表中的列</span></span><br><span class="line"><span class="comment">//        获取表中列的总数</span></span><br><span class="line">            <span class="keyword">int</span> columnCount = metaData.getColumnCount();</span><br><span class="line"><span class="comment">//            用来存放我们查询的信息对应的实体类</span></span><br><span class="line">            list = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">            <span class="comment">//判断是否有记录,然后再根据列名获取每列的信息</span></span><br><span class="line">            <span class="keyword">while</span> (resultSet.next())</span><br><span class="line">            &#123;<span class="comment">//每次循环获取的是一列数据</span></span><br><span class="line">                <span class="comment">//我们现在不能确定传入的实体类,这里用泛型替代,当你传入实体类型时确定</span></span><br><span class="line">                T t = clazz.newInstance();</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= columnCount; i++)<span class="comment">//循环要从1开始</span></span><br><span class="line">                &#123;<span class="comment">//遍历列数,获取每一列的名字</span></span><br><span class="line">                    String columnLabel = metaData.getColumnLabel(i);<span class="comment">//列名</span></span><br><span class="line"><span class="comment">//                通过列名获取对应列的数据</span></span><br><span class="line">                    Object object = resultSet.getObject(columnLabel);</span><br><span class="line"><span class="comment">//                    通过列名获取实体类中的属性名</span></span><br><span class="line">                    Field field = clazz.getDeclaredField(columnLabel);</span><br><span class="line"><span class="comment">//                    给获取的实体类的属性赋值</span></span><br><span class="line">                    field.setAccessible(<span class="keyword">true</span>);<span class="comment">//取消安全检查</span></span><br><span class="line">                    field.set(t, object);<span class="comment">//给t对象设置从数据库中查询出来的object值</span></span><br><span class="line">                    field.setAccessible(<span class="keyword">false</span>);<span class="comment">//开启安全检查</span></span><br><span class="line">                &#125;</span><br><span class="line">                list.add(t);<span class="comment">//把得到的实体类存入集合</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e)</span><br><span class="line">        &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">finally</span></span><br><span class="line">        &#123;</span><br><span class="line"><span class="comment">//            关闭连接</span></span><br><span class="line">            close(connection, statement, resultSet);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> list;<span class="comment">//返回实体类集合</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">//    关闭连接的方法</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">close</span><span class="params">(Connection connection, Statement statement, ResultSet resultSet)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">try</span></span><br><span class="line">        &#123;</span><br><span class="line"><span class="comment">//            如果连接不为空就关闭</span></span><br><span class="line">            <span class="keyword">if</span> (connection != <span class="keyword">null</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                connection.close();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (statement != <span class="keyword">null</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                statement.close();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (resultSet != <span class="keyword">null</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                resultSet.close();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e)</span><br><span class="line">        &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="创建表对应的实体类"><a href="#创建表对应的实体类" class="headerlink" title="创建表对应的实体类"></a>创建表对应的实体类</h2><p>我这里准备了2个，根据你自己的情况操作</p>
<p>Admin.java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span>: TODO(实体类, 对应数据库中表的列)</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> da</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2021/7/9 上午 11:44</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Admin</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> String pwd;</span><br><span class="line">	<span class="comment">//这里省略了get/set和toString方法,记得要有</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>Login.java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span>: TODO(这里用一句话描述这个类的作用)</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> da</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2021/7/9 下午 12:18</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Login</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> String password;</span><br><span class="line">    <span class="keyword">private</span> Integer age;</span><br><span class="line">    <span class="comment">//这里省略了get/set和toString方法,记得要有</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="到这里就完成了"><a href="#到这里就完成了" class="headerlink" title="到这里就完成了"></a>到这里就完成了</h2><p>最后就是测试成不成功，一切顺利的话你就可以像文章开始那样操作数据库了，可以简化一些重复的代码，让代码更加的简洁。</p>

        </div>

        
            <div class="post-copyright-info">
                <div class="article-copyright-info-container">
    <ul>
        <li>本文标题：JDBC操作封装工具类</li>
        <li>本文作者：Da</li>
        <li>创建时间：2021-07-09 12:21:54</li>
        <li>
            本文链接：https://da9527.gitee.io/2021/07/09/JDBC操作封装工具类/
        </li>
        <li>
            版权声明：本博客所有文章除特别声明外，均采用 <a class="license" target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">BY-NC-SA</a> 许可协议。转载请注明出处！
        </li>
    </ul>
</div>

            </div>
        

        
            <div class="article-nav">
                
                    <div class="article-prev">
                        <a class="prev"
                           rel="prev"
                           href="/2021/08/01/%E7%AE%80%E5%8D%95%E6%A8%A1%E6%8B%9Fmustache%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E%E5%AE%9E%E7%8E%B0/"
                        >
                            <span class="left arrow-icon flex-center">
                              <i class="fas fa-chevron-left"></i>
                            </span>
                            <span class="title flex-center">
                                <span class="post-nav-title-item">简单模拟mustache模板引擎实现</span>
                                <span class="post-nav-item">上一篇</span>
                            </span>
                        </a>
                    </div>
                
                
                    <div class="article-next">
                        <a class="next"
                           rel="next"
                           href="/2021/07/08/%E6%89%8B%E5%86%99%E5%87%A0%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84Android-Butterknife%E6%B3%A8%E8%A7%A3%E5%8A%9F%E8%83%BD/"
                        >
                            <span class="title flex-center">
                                <span class="post-nav-title-item">手写几个简单的Android Butterknife注解功能</span>
                                <span class="post-nav-item">下一篇</span>
                            </span>
                            <span class="right arrow-icon flex-center">
                              <i class="fas fa-chevron-right"></i>
                            </span>
                        </a>
                    </div>
                
            </div>
        

        
    </div>
</div>


                
            </div>

        </div>

        <div class="page-main-content-bottom">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info info-item">
            &copy;
            
              <span>2020</span>&nbsp;-&nbsp;
            
            2021&nbsp;<i class="fas fa-heart icon-animate"></i>&nbsp;<a href="/">Da</a>
        </div>
        
            <script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            <div class="website-count info-item">
                
                    <span id="busuanzi_container_site_uv">
                        访问人数&nbsp;<span id="busuanzi_value_site_uv"></span>&ensp;
                    </span>
                
                
                    <span id="busuanzi_container_site_pv">
                        总访问量&nbsp;<span id="busuanzi_value_site_pv"></span>
                    </span>
                
            </div>
        
        <div class="theme-info info-item">
            由 <a target="_blank" href="https://hexo.io">Hexo</a> 驱动&nbsp;|&nbsp;主题&nbsp;<a class="theme-version" target="_blank" href="https://github.com/XPoet/hexo-theme-keep">Keep v3.4.2</a>
        </div>
        
    </div>
</footer>

        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="tools-list">
        <!-- TOC aside toggle -->
        
            <li class="tools-item page-aside-toggle">
                <i class="fas fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
    </ul>
</div>

        </div>
    

    <div class="right-bottom-side-tools">
        <div class="side-tools-container">
    <ul class="side-tools-list">
        <li class="tools-item tool-font-adjust-plus flex-center">
            <i class="fas fa-search-plus"></i>
        </li>

        <li class="tools-item tool-font-adjust-minus flex-center">
            <i class="fas fa-search-minus"></i>
        </li>

        <li class="tools-item tool-expand-width flex-center">
            <i class="fas fa-arrows-alt-h"></i>
        </li>

        <li class="tools-item tool-dark-light-toggle flex-center">
            <i class="fas fa-moon"></i>
        </li>

        <!-- rss -->
        

        
            <li class="tools-item tool-scroll-to-top flex-center">
                <i class="fas fa-arrow-up"></i>
            </li>
        

        <li class="tools-item tool-scroll-to-bottom flex-center">
            <i class="fas fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="exposed-tools-list">
        <li class="tools-item tool-toggle-show flex-center">
            <i class="fas fa-cog fa-spin"></i>
        </li>
        
    </ul>
</div>

    </div>

    
        <aside class="page-aside">
            <div class="post-toc-wrap">
    <div class="post-toc">
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AF%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E5%A2%9E%E5%88%A0%E6%94%B9%E6%9F%A5%E8%BF%9B%E8%A1%8C%E7%AE%80%E5%8D%95%E7%9A%84%E5%B0%81%E8%A3%85"><span class="nav-text">对数据库的增删改查进行简单的封装</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%80%E5%A7%8B%E5%B0%81%E8%A3%85"><span class="nav-text">开始封装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%80%E4%B8%BB%E8%A6%81%E7%9A%84%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="nav-text">最主要的工具类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E8%A1%A8%E5%AF%B9%E5%BA%94%E7%9A%84%E5%AE%9E%E4%BD%93%E7%B1%BB"><span class="nav-text">创建表对应的实体类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%B0%E8%BF%99%E9%87%8C%E5%B0%B1%E5%AE%8C%E6%88%90%E4%BA%86"><span class="nav-text">到这里就完成了</span></a></li></ol></li></ol>
    </div>
</div>
        </aside>
    

    <div class="image-viewer-container">
    <img src="">
</div>


    
        <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
          <span class="search-input-field-pre">
            <i class="fas fa-keyboard"></i>
          </span>
            <div class="search-input-container">
                <input autocomplete="off"
                       autocorrect="off"
                       autocapitalize="off"
                       placeholder="搜索..."
                       spellcheck="false"
                       type="search"
                       class="search-input"
                >
            </div>
            <span class="popup-btn-close">
                <i class="fas fa-times"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fas fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>

    

</main>




<script src="/js/utils.js"></script>

<script src="/js/main.js"></script>

<script src="/js/header-shrink.js"></script>

<script src="/js/back2top.js"></script>

<script src="/js/dark-light-toggle.js"></script>



    
<script src="/js/local-search.js"></script>




    
<script src="/js/code-copy.js"></script>




    
<script src="/js/lazyload.js"></script>



<div class="post-scripts pjax">
    
        
<script src="/js/left-side-toggle.js"></script>

<script src="/js/libs/anime.min.js"></script>

<script src="/js/toc.js"></script>

    
</div>


    
<script src="/js/libs/pjax.min.js"></script>

<script>
    window.addEventListener('DOMContentLoaded', () => {
        const pjax = new Pjax({
            selectors: [
                'head title',
                '.page-container',
                '.pjax'
            ],
            history: true,
            debug: false,
            cacheBust: false,
            timeout: 0,
            analytics: false,
            currentUrlFullReload: false,
            scrollRestoration: false,
            // scrollTo: true,
        });

        document.addEventListener('pjax:send', () => {
            KEEP.utils.pjaxProgressBarStart();
        });

        document.addEventListener('pjax:complete', () => {
            KEEP.utils.pjaxProgressBarEnd();
            pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
            KEEP.refresh();
        });
    });
</script>



<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":120,"height":240},"mobile":{"show":false},"log":false});</script></body>
</html>
